package activiti;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

/**
 * 流程变量的设置
 * @author Shea
 *
 */
public class ProcessVar {
	//设置流程引擎对象
	ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();
	/**
	 * 启动实例时设置流程变量
	 */
	@Test
	public void startInstance(){
		//创建hashmap,设置变量值
		HashMap<String, Object> variables = new HashMap<>();
		variables.put("bxje", 500);
		variables.put("reason", "出差北京");
//		processEngine.getRuntimeService().startProcessInstanceByKey("",variables);
		//ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("qjlc", variables);
		ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById("qjlc:2:104");
		System.out.println(instance.getId());
	}
	/**
	 * 办理任务值设置流程变量
	 */
	@Test
	public void dealTask(){
		HashMap<String, Object> variables = new HashMap<>();
		variables.put("pass", "金额属实,通过");
		processEngine.getTaskService().complete("1202", variables);
	}
	
	/**
	 * 调用taskservice时设置流程变量-------与办理任务时差不多
	 */
	@Test
	public void taskService(){
		HashMap<String, Object> variables = new HashMap<>();
		variables.put("pass", "金额属实,通过");
		processEngine.getTaskService().setVariables("1003", variables);	
	}
	
	/**
	 * 获取流程变量
	 */
	@Test
	public void getVar(){
		Map<String, Object> variables = processEngine.getTaskService().getVariables("1003");
		System.out.println(variables);
	}
}
